//
//  SourceListElement.m
//  SolarSeek
//
//  Created by Erick Fejta on 05/03/15.
//  Copyright 2005 Erick Fejta. All rights reserved.
//

#import "SourceListElement.h"
#import "SolarSeekApplication.h"
#import "ApplicationDefaults.h"

NSMutableParagraphStyle *defaultStyle = nil;
float defaultSize = 13;
NSAttributedString *noText=nil; 

@implementation SourceListElement 

+ (void)initialize {
	defaultStyle = [[NSMutableParagraphStyle alloc] init];
	[defaultStyle setAlignment:NSLeftTextAlignment];
	[defaultStyle setLineBreakMode:NSLineBreakByTruncatingMiddle];
	
	noText = [[NSAttributedString alloc] initWithString:@""];
}

+ (float)defaultSize { return [[NSUserDefaults standardUserDefaults] floatForKey:SolarSeekDefaultSizeFontSourceList]; }
+ (NSParagraphStyle *)defaultStyle {	return defaultStyle; }

- (NSImage *)icon { return nil; } //fejta: TODO: low: add default icon of sorts.
- (NSString *)name { return @"Undefined Element"; }

+ (NSAttributedString *)nameAttributedForElement:(id<SourceListElement>) element {
	BOOL bold = [element isRequestingAttention] && [NSApp selectedSourceListElement]!=self;
	return [[[NSAttributedString alloc] 
		initWithString:[element name] 
		attributes:[NSDictionary dictionaryWithObjectsAndKeys:
				bold?[NSFont boldSystemFontOfSize:[SourceListElement defaultSize]]:[NSFont systemFontOfSize:[SourceListElement defaultSize]],NSFontAttributeName
				,[SourceListElement defaultStyle],NSParagraphStyleAttributeName
				,nil]
			] autorelease]; 
}

- (NSAttributedString *)nameAttributed { 
	_bold = [self isRequestingAttention] && [NSApp selectedSourceListElement]!=self;
	return [SourceListElement nameAttributedForElement:self]; 
}


- (NSString *)titleWindow { return [self name]; }
- (NSAttributedString *)text { return noText; }
- (NSArray *)buttons { return [NSArray array]; }

- (NSArray *)conversations { return [NSArray array]; }
- (NSArray *)participants { return [NSArray array]; }
- (NSArray *)searches { return [NSArray array]; }
- (NSArray *)shares { return [NSArray array]; }

- (void)refresh {
	[self refreshAndRequestAttention:NO];
}

- (void)refreshAndRequestAttention:(BOOL)ask {
	_bold = _bold || ask;
	[NSApp updateSourceListElement:self];
}


- (BOOL)isRequestingAttention { return _bold; }
- (BOOL)isSelected { return _selected; }
- (void)setSelected:(BOOL)selected { _selected = selected; }

@end

@implementation SourceListArrayElement 
- (NSImage *)icon { return nil; } //fejta: TODO: low: add default icon of sorts.

- (NSString *)name { 	return @"Undefined Array Element"; }

- (NSAttributedString *)nameAttributed { 
	_bold = [self isRequestingAttention] && [NSApp selectedSourceListElement]!=self;
	return [SourceListElement nameAttributedForElement:self]; 
}

- (NSString *)titleWindow { return [self name]; }
- (NSArray *)buttons { return [NSArray array]; }

- (NSArray *)conversations { return [NSArray array]; }
- (NSArray *)participants { return [NSArray array]; }
- (NSArray *)participantsSelected { return [NSArray array]; }
- (NSArray *)searches { return [NSArray array]; }
- (NSArray *)shares { return [NSArray array]; }
- (NSAttributedString *)text { return noText; }

- (BOOL)isSelected { return _selected; }
- (void)setSelected:(BOOL)selected { _selected = selected; }


- (void)refresh {
	[self refreshAndRequestAttention:NO];
}

- (void)refreshAndRequestAttention:(BOOL)ask {
	//fejta: TODO: this should report this information to the parent.
	_bold = _bold || ask;
	[NSApp updateSourceListElement:self];
}

- (BOOL)isRequestingAttention { return _bold; }

+ (float)defaultSize { return [SourceListElement defaultSize]; }
+ (NSParagraphStyle *)defaultStyle { return [SourceListElement defaultStyle]; }

@end
